class Solution
{
	int count;
	int ret;
public:
	int kthSmallest(TreeNode* root, int k)
	{
		count = k;
		
			dfs(root);
		return ret;
	}
	void dfs(TreeNode* root)
	{
		if (root == nullptr || count == 0) return;
		dfs(root->left);
		count--;
		if (count == 0) ret = root->val;
		dfs(root->right);
	}
};